package com.lv.LvTourismModel.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.aqgj.User.bean.User;
import com.lv.LvTourismForSale.bean.LvTourismForSale;
import com.lv.LvTourismForSale.service.LvTourismForSaleManager;
import com.lv.LvTourismModel.bean.LvTourismModel;
import com.lv.LvTourismModel.service.LvTourismModelManager;
import com.ztc.ZtcCar.bean.ZtcCar;
import com.ztc.ZtcClasses.bean.ZtcClasses;
import com.ztc.ZtcClassesForSale.bean.ZtcClassesForSale;
import com.ztc.ZtcClassesSite.bean.ZtcClassesSite;
import com.ztc.ZtcTransport.bean.ZtcTransport;
import com.ztc.ZtcTransport.service.ZtcTransportManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("lvTourismModelAction")
public class LvTourismModelAction{
    @Autowired
    private LvTourismModelManager lvTourismModelManager;
    @Autowired
    private LvTourismForSaleManager lvTourismForSaleManager;
    @Autowired
    private ZtcTransportManager ztcTransportManager;
    private static final Logger log = LogManager.getLogger(LvTourismModel.class);
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * 添加旅游模板
     * @param lvTourismModel 旅游模板对象
     * @param priceComboData 价格套餐json集合
     * @param pictureData 图片json集合
     * @param attachmentData 附件json集合
     * @param session
     * @param request
     * @return
     */
    @RequestMapping("sign")
    @ResponseBody
    public HashMap<String, Object> save(LvTourismModel lvTourismModel,String priceComboData, String pictureData, String attachmentData, HttpSession session, HttpServletRequest request){
        log.info("开始添加");
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
      /*  int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.save(lvTourismModel,priceComboData,pictureData,attachmentData,user,transport,request);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "添加失败");
            log.info("添加失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "添加成功");
        log.info("添加成功");
        return wapper;
    }

    /**
     * 发布前修改
     * @param lvTourismModel 旅游模板对象
     * @param priceComboData 价格套餐json集合
     * @param pictureData 图片json集合
     * @param attachmentData 附件json集合
     * @param session
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public HashMap<String, Object> update(LvTourismModel lvTourismModel,String priceComboData,String pictureData, String attachmentData,HttpSession session){
        log.info("开始修改");
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
      /*  int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.update(lvTourismModel,priceComboData,pictureData,attachmentData,user);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "修改失败");
            log.info("修改失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "修改成功");
        log.info("修改成功");
        return wapper;
    }

    /**
     * 发布后修改
     * @param lvTourismModel 旅游模板对象
     * @param priceComboData 价格套餐json集合
     * @param pictureData 图片json集合
     * @param attachmentData 附件json集合
     * @param session
     * @return
     */
    @RequestMapping("updateSell")
    @ResponseBody
    public HashMap<String, Object> updateSell(LvTourismModel lvTourismModel,String priceComboData,String pictureData, String attachmentData,HttpSession session){
        log.info("开始修改");
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
      /*  int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.updateSell(lvTourismModel,priceComboData,pictureData,attachmentData,user);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "修改失败");
            log.info("修改失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "修改成功");
        log.info("修改成功");
        return wapper;
    }
    /**
     * 发布后生成在售旅游
     * @param lvTourismModel 旅游模板对象
     * @param session
     * @return
     */
    @RequestMapping("generateSell")
    @ResponseBody
    public HashMap<String, Object> generateSell(LvTourismModel lvTourismModel,HttpSession session){
        log.info("开始修改");
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
      /*  int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.generateSell(lvTourismModel,user);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "修改失败");
            log.info("修改失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "修改成功");
        log.info("修改成功");
        return wapper;
    }

    /**
     * 发布前生成在售旅游
     * @param lvTourismModel 旅游模板对象
     * @param session
     * @return
     */
    @RequestMapping("generate")
    @ResponseBody
    public HashMap<String, Object> generate(LvTourismModel lvTourismModel, HttpSession session){
        log.info("开始发布");
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.generate(lvTourismModel,user);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "生成失败");
            log.info("生成失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "生成成功");
        wapper.put("result",JSON.parseArray(result));
        log.info("生成成功");
        return wapper;
    }

    /**
     * 根据id获取旅游模板及其价格套餐，滚动图片，附件
     * @param id 旅游模板id
     * @param session
     * @return
     */
    @RequestMapping("getById")
    @ResponseBody
    public HashMap<String, Object> getById(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        HashMap<String,Object> result=lvTourismModelManager.getById(id);
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("lvTourismModel", result.get("lvTourismModel"));
        wapper.put("priceComboData", result.get("priceComboData"));
        wapper.put("pictureData", result.get("pictureData"));
        wapper.put("attachmentData", result.get("attachmentData"));
        return wapper;
    }

    /**
     * 获取旅游模板及其价格套餐
     * @param id 旅游模板id
     * @return
     */
    @RequestMapping("getModelAndPriceById")
    @ResponseBody
    public HashMap<String, Object> getModelAndPriceById(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        HashMap<String,Object> result=lvTourismModelManager.getModelAndPriceById(id);
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("lvTourismModel", result.get("lvTourismModel"));
        wapper.put("priceComboData", result.get("priceComboData"));
        return wapper;
    }

    /**
     * 获取旅游模板及其从当前时间往后的在售旅游
     * @param id 旅游模板id
     * @param session
     * @return
     */
    @RequestMapping("getModelAndForSaleById")
    @ResponseBody
    public HashMap<String, Object> getModelAndForSaleById(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        HashMap<String,Object> result=lvTourismModelManager.getModelAndForSaleById(id);
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("lvTourismModel", result.get("lvTourismModel"));
        wapper.put("lvTourismForSaleList", result.get("lvTourismForSaleList"));
        return wapper;
    }

    /**
     * 获取旅游模板及其指定时间范围内在售旅游
     * @param id 旅游模板id
     * @param year 年
     * @param month 月
     * @param session
     * @return
     */
    @RequestMapping("getModelAndForSaleByIdAndMonth")
    @ResponseBody
    public HashMap<String, Object> getModelAndForSaleByIdAndMonth(String id,String year,String month, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        HashMap<String,Object> result=lvTourismModelManager.getModelForSaleByIdAndMonth(id,year,month);
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("lvTourismForSaleList", result.get("lvTourismForSaleList"));
        return wapper;
    }

    /**
     * 旅游模板发布
     * @param id 旅游模板id
     * @param session
     * @return
     */
    @RequestMapping("publish")
    @ResponseBody
    public HashMap<String, Object> publish(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.publish(id);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "发布失败");
            log.info("发布失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "发布成功");
        log.info("发布成功");
        return wapper;
    }

    /**
     * 旅游魔板取消在售旅游
     * @param id 旅游模板id
     * @param session
     * @return
     */
    @RequestMapping("cancel")
    @ResponseBody
    public HashMap<String, Object> cancel(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.cancel(id);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "取消失败");
            log.info("取消失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "取消成功");
        log.info("取消成功");
        return wapper;
    }
    /**
     * 删除旅游模板
     * @param id 旅游模板id
     * @param session
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public HashMap<String, Object> delete(String id, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String result=lvTourismModelManager.delete(id);
        if("0".equals(result)){
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "取消失败");
            log.info("取消失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "取消成功");
        log.info("取消成功");
        return wapper;
    }
    /**
     * 停售班次模板及其所有的在线班次
     * @param id 班次模板id
     * @param session
     * @return 操作结果信息
     * @throws ParseException
     */
    @RequestMapping("stopSell")
    @ResponseBody
    public HashMap<String, Object> stopSell(String id, HttpSession session) throws ParseException{
        Date now = new Date();
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
        int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        List<LvTourismForSale> lvTourismForSaleList=lvTourismForSaleManager.search(id,now,"0");
        for (int i = 0; i < lvTourismForSaleList.size(); i++) {
            LvTourismForSale lvTourismForSale = lvTourismForSaleList.get(i);
            lvTourismForSale.setStatus(1);
            lvTourismForSale.setFkModifyUserId(user.getId());
            lvTourismForSale.setModifyTime(now);
            String result = lvTourismForSaleManager.update(lvTourismForSale);
            if ("0".equals(result)) {
                wapper.put("success", Boolean.valueOf(false));
                wapper.put("msg", "停售失败");
                return wapper;
            }
        }
        //LvTourismModel lvTourismModel = lvTourismModelManager.get(id);
        // lvTourismModel.setFkModifyUserId(user.getId());
        LvTourismModel lvTourismModelBean=lvTourismModelManager.get(id);
        lvTourismModelBean.setModifyTime(now);
        lvTourismModelBean.setFkModifyUserId(user.getId());
        lvTourismModelBean.setStatus(5);
        String updateResult = lvTourismModelManager.update(lvTourismModelBean);
        if ("0".equals(updateResult)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "停售失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "停售成功");
        return wapper;
    }
    /**
     * 停售班次模板及其所有的在线班次
     * @param id 班次模板id
     * @param session
     * @return 操作结果信息
     * @throws ParseException
     */
    @RequestMapping("stopSellWithDate")
    @ResponseBody
    public HashMap<String, Object> stopSellWithDate(String id,String autoArrangeEndDate, HttpSession session) throws ParseException{
        Date now = new Date();
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
        int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        Date endDate=DATE_FORMAT.parse(autoArrangeEndDate);
        List<LvTourismForSale> lvTourismForSaleList=lvTourismForSaleManager.search(id,endDate,"0");
        for (int i = 0; i < lvTourismForSaleList.size(); i++) {
            LvTourismForSale lvTourismForSale = lvTourismForSaleList.get(i);
            lvTourismForSale.setStatus(1);
            lvTourismForSale.setFkModifyUserId(user.getId());
            lvTourismForSale.setModifyTime(now);
            String result = lvTourismForSaleManager.update(lvTourismForSale);
            if ("0".equals(result)) {
                wapper.put("success", Boolean.valueOf(false));
                wapper.put("msg", "停售失败");
                return wapper;
            }
        }
        LvTourismModel lvTourismModelBean=lvTourismModelManager.get(id);
        lvTourismModelBean.setAutoArrangeEndDate(endDate);
        lvTourismModelBean.setModifyTime(now);
        lvTourismModelBean.setFkModifyUserId(user.getId());
        lvTourismModelBean.setStatus(4);
        String updateResult = lvTourismModelManager.update(lvTourismModelBean);
        if ("0".equals(updateResult)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "停售失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "停售成功");
        return wapper;
    }
    /**
     * 获取旅游模板集合
     * @param pageNumber 第几页
     * @param pageSize 页行数
     * @param tourismName 景点名称
     * @param status 状态集合：0-起草，1-发布，2-停售
     * @param session
     * @return
     */
    @RequestMapping("getList")
    @ResponseBody
    public HashMap<String, Object> getList(String pageNumber,String pageSize,String tourismName,String status, HttpSession session){
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
       /* int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }*/
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        List<LvTourismModel> list=lvTourismModelManager.getList(pageNumber,pageSize,tourismName,status);
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("list", list);
        int count=lvTourismModelManager.getCount(tourismName,status);
        wapper.put("count",count);
        return wapper;
    }

    /**
     * 停售班次模板及其所有的在线班次
     * @param id 班次模板id
     * @param session
     * @return 操作结果信息
     * @throws ParseException
     */
    @RequestMapping("updateArrangeEndDate")
    @ResponseBody
    public HashMap<String, Object> updateArrangeEndDate(String id,String autoArrangeEndDate, HttpSession session) throws ParseException{
        Date now = new Date();
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
        int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        Date endDate=DATE_FORMAT.parse(autoArrangeEndDate);
        List<LvTourismForSale> lvTourismForSaleList=lvTourismForSaleManager.search(id,endDate,"0");
        for (int i = 0; i < lvTourismForSaleList.size(); i++) {
            LvTourismForSale lvTourismForSale = lvTourismForSaleList.get(i);
            lvTourismForSale.setStatus(1);
            lvTourismForSale.setFkModifyUserId(user.getId());
            lvTourismForSale.setModifyTime(now);
            String result = lvTourismForSaleManager.update(lvTourismForSale);
            if ("0".equals(result)) {
                wapper.put("success", Boolean.valueOf(false));
                wapper.put("msg", "停售失败");
                return wapper;
            }
        }
        LvTourismModel lvTourismModelBean=lvTourismModelManager.get(id);
        lvTourismModelBean.setAutoArrangeEndDate(endDate);
        lvTourismModelBean.setModifyTime(now);
        lvTourismModelBean.setFkModifyUserId(user.getId());
        lvTourismModelBean.setStatus(4);
        String updateResult = lvTourismModelManager.update(lvTourismModelBean);
        if ("0".equals(updateResult)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "停售失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "停售成功");
        return wapper;
    }
    /**
     * 起售班次模板及其所有的停售班次
     * @param id 班次模板id
     * @param session
     * @return 操作结果信息
     */
    @RequestMapping("quitStopSell")
    @ResponseBody
    public HashMap<String,Object> quitStopSell(String id,String autoArrangeEndDate,HttpSession session){
        Date now = new Date();
        HashMap<String, Object> wapper = new HashMap<>();
        User user = (User) session.getAttribute("userInfo");
        if (user == null || "".equals(user)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "用户未登录");
            log.info("用户未登录");
            return wapper;
        }
        ZtcTransport transport = ztcTransportManager.get(user.getTransportId());
        int transportType = transport.getType();
        if (transportType == 0 || transportType == 1 || transportType == 2) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "非旅游公司不可使用此功能");
            log.info("非旅游公司不可使用此功能");
            return wapper;
        }
        if (transport.getStatus() == 4) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "该用户公司已被冻结，不可使用此功能");
            log.info("该用户公司已被冻结，不可使用此功能");
            return wapper;
        }
        String updateResult = lvTourismModelManager.quitStopSell(id,autoArrangeEndDate,user.getId());
        if ("0".equals(updateResult)) {
            wapper.put("success", Boolean.valueOf(false));
            wapper.put("msg", "起售失败");
            return wapper;
        }
        wapper.put("success", Boolean.valueOf(true));
        wapper.put("data", "起售成功");
        return wapper;
    }
}